<!-- 项目列表 -->
<template>
    <div class="supply container-content">
        <div class="app-view-box">
            <el-row>
                <el-col :span="24">
                    <h1 class="panel-title">项目列表</h1>
                </el-col>
            </el-row>
            <el-row justify="end" class="export-container">
                <el-button
                    type="primary"
                    icon="el-icon-download"
                    size="mini"
                    @click="exporting"
                    >导出</el-button
                >
            </el-row>

            <el-table
                ref="customerTable"
                :data="tableData"
                stripe
                style="width: 100%"
                @selection-change="handleSelectionChange"
            >
                <el-table-column
                    type="selection"
                    width="55"
                    align="center"
                ></el-table-column>
                <el-table-column
                    prop="projectName"
                    label="项目名称"
                ></el-table-column>
                <el-table-column
                    prop="projectCode"
                    label="项目编码"
                ></el-table-column>
                <el-table-column
                    prop="deptId"
                    label="子公司id"
                ></el-table-column>
                <el-table-column
                    prop="deptName"
                    label="子公司名称"
                ></el-table-column>
                <el-table-column
                    prop="customerId"
                    label="所属客户"
                ></el-table-column>
                <el-table-column
                    prop="contactsPhone"
                    label="联系电话"
                ></el-table-column>
                <el-table-column
                    prop="responsibleUserId"
                    label="负责人"
                ></el-table-column>
                <el-table-column
                    prop="projectTypeId"
                    label="项目类型"
                ></el-table-column>
                <el-table-column label="操作" width="200">
                    <template slot-scope="scope">
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="详情"
                            placement="bottom"
                        >
                            <el-button
                                plain
                                icon="el-icon-more"
                                @click="handleDetail(scope.$index, scope.row)"
                                size="mini"
                            ></el-button>
                        </el-tooltip>
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="编辑"
                            placement="bottom"
                        >
                            <el-button
                                type="primary"
                                plain
                                icon="el-icon-edit"
                                size="mini"
                                @click="handleEdit(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="删除"
                            placement="bottom"
                        >
                            <el-button
                                type="danger"
                                plain
                                icon="el-icon-delete"
                                size="mini"
                                @click="handleDelete(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-pagination
            class="table-pagination"
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
        >
        </el-pagination>
    </div>
</template>
<script>
import { getProjectList } from "@/api/system/project";

export default {
    data() {
        return {
            tableData: [],
            searchValue: "",
            total: 0,
            selectRows: [],
        };
    },
    methods: {
        // 获取供应商列表
        getData() {
            // let type = 3;
            getProjectList().then((res) => {
                this.tableData = res.rows;
                this.total = res.total * 1;
            });
        },
        // 下拉菜单点击事件
        // handleCommand(command) {
        //   if (command === "add") {

        //   } else if (command === "edit") {
        //     if (this.selectRows.length !== 1) {
        //       this.$message.error("请选择一条数据进行编辑");
        //       return;
        //     } else {
        //       // 跳转编辑客户
        //       this.$router.push({ path: "/CustomerManager/EditCustomer" });
        //     }
        //   } else if (command === "delete") {
        //     if (this.selectRows.length === 0) {
        //       this.$message.error("请选择您需要删除的记录！");
        //       return;
        //     } else {
        // this.$confirm("请确定要删除所选的记录吗？", "提示", {
        //   confirmButtonText: "确定",
        //   cancelButtonText: "取消",
        //   type: "warning",
        // })
        //   .then(() => {
        //     this.$message({
        //       type: "success",
        //       message: "删除成功!",
        //     });
        //     // deleteCustomer({ids:}).then(res=>{

        //     // })
        //     // this.tableData.splice()
        //   })
        //   .catch(() => {
        //     this.$message({
        //       type: "info",
        //       message: "已取消删除",
        //     });
        //   });
        //       console.log("this.selectRows", this.selectRows);
        //     }
        //     // 跳转删除客户
        //     console.log("删除客户");
        //     // this.$router.push({ path: "/CustomerManager/AddCustomer" });
        //   }
        //   // this.$message("点击" + command);
        // },
        //新增客户
        addCustomer() {
            // this.$router.push({ path: "/CustomerManager/AddCustomer" });
        },
        //客户详情
        handleDetail(index, row) {
            // this.$router.push({
            //   path: "/CustomerManager/CustomerDetail",
            //   query: { id: row.id },
            // });
        },
        // 编辑客户
        handleEdit(index, row) {
            // this.$router.push({
            //   path: "/CustomerManager/EditCustomer",
            //   query: { id: row.id },
            // });
        },

        // 删除客户
        handleDelete(index, row) {
            this.$confirm("请确定要删除所选的记录吗？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    deleteProject(row.id).then((res) => {
                        if (res.code === 200) {
                            this.tableData.splice(index, 1);
                            this.$message({
                                type: "success",
                                message: "删除成功!",
                            });
                            this.getData();
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
        // 导出按钮
        exporting() {
            console.log("exporting");
        },
        // 表格checkcbox事件
        handleSelectionChange(rows) {
            this.selectRows = rows;
        },
    },

    created() {
        this.getData();
    },
};
</script>
<style lang="scss" scoped>
.filter-container {
    margin-bottom: 15px;
}

.export-container {
    margin: 15px 0;
}

.panel-title {
    font-size: 18px;
    color: #37474f;
    font-weight: 500;
    text-shadow: rgba(0, 0, 0, 0.15) 0 0 1px;
}

.divider {
    margin: 0;
}
</style>
